package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

//数仓第三方代销
type CM_CUST_FDX_INVEST_M struct {
	JLID int        `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	SJRQ *time.Time `gorm:"column:数据日期;type:date;"`
	KHMC string     `gorm:"column:客户名称"`
	//	KH     string     `gorm:"column:卡号;"`
	ZJHM   string   `gorm:"column:证件号码;"`
	SSJG   string   `gorm:"column:所属机构;"`
	CPDM   string   `gorm:"column:产品代码"`
	JYXZ   string   `gorm:"column:交易性质;"`
	CPZT   string   `gorm:"column:产品状态;"`
	BZ     string   `gorm:"column:币种;"`
	DQFE   *float64 `gorm:"column:当前份额"`
	DYGMJE *float64 `gorm:"column:当月购买金额;"`
	LCZH   string   `gorm:"column:理财账号"`
	CUID   int      `gorm:"column:CUID"`
	YG1    string   `gorm:"-"`
	ZB1    *float64 `gorm:"-"`
	YG2    string   `gorm:"-"`
	ZB2    *float64 `gorm:"-"`
	YG3    string   `gorm:"-"`
	ZB3    *float64 `gorm:"-"`
	YG4    string   `gorm:"-"`
	ZB4    *float64 `gorm:"-"`
	YG5    string   `gorm:"-"`
	ZB5    *float64 `gorm:"-"`
}

//TableName User用户表名
func (CM_CUST_FDX_INVEST_M) TableName() string {
	return "V_CM_CUST_FDX_INVEST_M"
}

// AfterFind 选择男女

func (c *CM_CUST_FDX_INVEST_M) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("indi_qtzb_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision("12:" + strconv.Itoa(c.JLID))
	if err != nil {
		return
	}
	i := 0
	if diviMap == nil || len(diviMap) == 0 {
		share, err = cube.GetShare("indi_clie_divi")
		if err != nil {
			return
		}
		diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
		if err != nil {
			return
		}
	}
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

func CM_CUST_FDX_INVEST_MEF() base.EntityFunc {
	return func() interface{} {
		entity := CM_CUST_FDX_INVEST_M{}
		return &entity
	}
}
func CM_CUST_FDX_INVEST_MESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CM_CUST_FDX_INVEST_M
		return &entities
	}
}

func init() {
	dao := base.NewDefaultDao(CM_CUST_FDX_INVEST_MEF(), CM_CUST_FDX_INVEST_MESF(), nil)
	filter := base.DefaultFilter{
		// FilterColName: "JLID",
		// TableName:     "T_INDI_CLIE_DIVI",
		// EmidColName:   "emid",
		// AcidColName:   "CUID",
		// WhereCause:    "ywid=12",
		FilterColName: "CUID",
		TableName:     "T_INDI_CLIE_YGFC",
		EmidColName:   "emid",
		AcidColName:   "CUID",
		WhereCause:    "DTID=dbo.GetDateToInt(dbo.GetCurSysDate())",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("CM_CUST_FDX_INVEST_M", dao)
}
